package com.huawei.hwid.core.d.b;

import android.content.Context;
import android.util.Log;
import com.huawei.hwid.core.d.g;
import java.io.File;

public final class d extends b {
    private static final a b = new a();
    private static String c = b.a();
    private static d d;

    static class a extends Thread {
        private Context a;

        a(Context context) {
            this.a = context;
        }

        public void run() {
            String str = "";
            try {
                str = a.a(this.a);
            } catch (ArrayIndexOutOfBoundsException e) {
                Log.e("hwid", "ArrayIndexOutOfBoundsException" + e.getMessage());
                return;
            } catch (Exception e2) {
                Log.e("hwid", "Exception" + e2.getClass().getSimpleName());
                return;
            } finally {
                a.c(this.a);
            }
            Log.i("hwid", "deleteLogFile");
            d.b(str);
            d.b.a(new File(str, "hwid_advanced_log.txt"));
            c.a(d.b);
        }
    }

    private d(Context context) {
        new a(context).start();
    }

    public static synchronized d b(Context context) {
        d dVar;
        synchronized (d.class) {
            if (d == null) {
                d = new d(context);
                c = b.a(context);
            }
            dVar = d;
        }
        return dVar;
    }

    private static void b(String str) {
        File file = new File(str, "apphwid.txt");
        File file2 = new File(str, "apphwid.txt.bak");
        g.a(file);
        g.a(file2);
    }

    private static synchronized void a(int i, String str, String str2, Throwable th, int i2) {
        synchronized (d.class) {
            if (a(i)) {
                if (str2 == null) {
                    try {
                        str2 = "";
                    } catch (IllegalArgumentException e) {
                        Log.e("hwid", "println IllegalArgumentException" + e.getMessage());
                    } catch (Exception e2) {
                        Log.e("hwid", "println Exception" + e2.getClass().getSimpleName());
                    }
                }
                Log.println(i, c + str, str2);
            }
        }
    }

    private static boolean a(int i) {
        return Log.isLoggable("hwid", i);
    }

    public void a(String str, String str2) {
        a(3, str, str2, null, 2);
    }

    public void b(String str, String str2) {
        a(4, str, str2, null, 2);
        c.a(str, str2);
    }

    public void c(String str, String str2) {
        a(6, str, str2, null, 2);
        c.b(str, str2);
    }
}
